<?

$files = array(
	'../sources/red.sparkle.css' => '../release/red.sparkle.min.css',
	'../sources/red.sparkle.ie.css' => '../release/red.sparkle.ie.min.css',
);

$ver = '../VERSION';

$hdr = 
'/*
	Copyright (c) 2011 Andrey O. Zbitnev (azbitnev@gmail.com)
	Licensed under the MIT License (LICENSE).

	Project home: http://code.google.com/p/red-sparkle/

	Version: ' . file_get_contents($ver) . '
*/
';

class css_packer {

	protected static function replacement($m) {
		$h = preg_replace('/[\s\r\n\t]+/m', ' ', trim($m[1]));
		$h = preg_replace('/\s*([:;])\s*/', '$1', $h);
		$h = preg_replace('/;$/', '', $h);
		$h = preg_replace('/:0(em|px|pt)$/', ':0', $h);
		return '{' . $h . '}';
	}

	public static function pack($css, $keep_comments = true) {
		$css = preg_replace_callback('/\{((?:[^\}]|[\s\t\r\n])*)\}/m', array('css_packer', 'replacement'), $css);
		if (!$keep_comments)
			$css = preg_replace('/\/\*((?:.|[\s\t\r\n])*?)\*\//m', '', $css);
		$css = preg_replace('/[\r\n]+/', "\n", $css);
		return trim($css);
	}
}

foreach ($files as $src => $dst) {
	$css = file_get_contents($src);
	$css = $hdr . css_packer::pack($css, false);
	file_put_contents($dst, $css);
}

?>